﻿using System;
using System.Collections.Generic;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;

namespace MCPlatform.Communicate.Modbus
{
    public class ModbusRTUMasterInfo
    {

        [JsonIgnore]
        public SerialPort? Port { get; set; }

        public string? PortName { get; set; }
        public int BaudRate { get; set; }=9600;

        public int DataBits { get; set; } = 8;

        public Parity Parity { get; set; } = Parity.None;

        public StopBits StopBits { get; set; } = StopBits.One;
        public byte SlaveAddr { get; set; } = 1;

        public string? SlaveName { get; set; } = null;

        public bool IsAutoRetry { get; set; }

        public void PropertiesDataToPort()
        {
            if (Port == null) return;
            Port.BaudRate = BaudRate;
            Port.DataBits = DataBits;
            Port.Parity = Parity;
            Port.StopBits = StopBits;
        }

        public void PortDataToProperties()
        {
            if (Port == null) return;
            BaudRate = Port.BaudRate;
            DataBits = Port.DataBits;
            Parity = Port.Parity;
            StopBits = Port.StopBits;
        }

    }
}
